<template>
	<view class="work-item" hover-class="active" @tap="workClick">
		<image mode="widthFix" class="bg" src='../static/bg1.png'></image>
		<view class='content'>
			<view class="item-title">
				<view>{{item.name}}</view>
			</view>
			<view class="item-pay">
				{{item.pay}}
			</view>
			<view class="describe">
				<!-- <text>{{item.companyName ? item.companyName : '暂无'}}</text> -->
				<text>招聘人数：{{item.peopleCount ? item.peopleCount : 0}}人</text>
				<!-- <text>未融资</text> -->
			</view>
			<view class="tags">
				要求：
				<text class="tag" v-for="(items,index) in tagsList" :key="index">
					{{items}}
				</text>
			</view>
			<view class="boss">
				<view class="info">
					<!-- <view class="pic">
		      <image src="../static/uni.png" mode=""></image>
		    </view> -->
					<!-- <view class="name">
		      {{item.corporateContacts || '招聘者'}}
		    </view> -->
					<!-- 地址： -->
				</view>
				<!-- <text class="place">{{item.district}} {{item.address}}</text> -->
				<!-- <text class="place">{{item.site ? item.site : '暂无'}}</text> -->
			</view>
			<slot></slot>
		</view>

	</view>
</template>

<script>
	import store from '../store/index.js';
	import {
		mapState
	} from 'vuex';
	export default {
		name: "workItem",
		props: {
			item: {
				type: Object,
				default: {},
				required: true
			}
		},
		data() {
			return {
				tagsList: [
					'3-5年',
					'大专以上',
					'开发'

				],
				user_token: ''
			};
		},
		mounted() {
			this.tagsList = [this.item.workExperience, this.item.educationalRequirements].splice(0, 5)
			this.user_token = uni.getStorageSync('user_token');
		},
		methods: {
			getLogin() {
				let that = this;
				wx.login({
					success: res => {
						this.code = res.code;
						if (this.code) {
							let params = {
								code: this.code
							}
							this.$api.get_ready_auth(params).then(res => {
								if (res.code === 200) {
									uni.removeStorageSync('user_token');
									uni.setStorageSync('user_token', res.data.accessToken);
									uni.navigateTo({
										url: "../workDetail/workDetail?detail=" + encodeURIComponent(JSON.stringify(this.item)),
									})
								} else {
									uni.showModal({
										title: '温馨提示',
										content: '请先授权登录',
										confirmText: '同意',
										cancelText: '关闭',
										success: function(res) {
											if (res.confirm) {
												uni.navigateTo({
													// 保留当前页面，跳转到应用内的某个页面,使用uni.navigateBack可以返回到原页面
													url: "/pages/auth/auth"
												})
											} else if (res.cancel) {
												console.log('关闭');
											}
										}
									});
								}
							})
						}
					}
				})
			},
			workClick() {
				if (!this.user_token) {
					this.getLogin();
				} else {
					uni.navigateTo({
						url: "../workDetail/workDetail?detail=" + encodeURIComponent(JSON.stringify(this.item)),
					})
				}
				
			}
		}
	}
</script>

<style lang="scss">
	.work-item {
		width: 100%;
		height: 100%;
		// width: 680rpx;
		// padding: 30rpx 35rpx;
		margin: auto;
		// background: $uni-bg-color;
		// background: url("@/static/bg1.png") no-repeat center center;
		background-size: 100%;
		margin-bottom: 10rpx;
		border-radius: 5px;
		box-shadow: 0 1rpx 0 0 rgba(0, 0, 0, 0.06);
		position: relative;

		.bg {
			width: 50%;
			hegiht: 50%;
			// width: 100rpx;
			// hegiht: 100rpx;
			position: absolute;
			// right: 0;
			// bottom: 0;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			z-index: 0;
			// padding: 30rpx 35rpx;
		}

		.content {
			width: 100%;
			hegiht: 100%;
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			z-index: 1;
			padding: 20rpx;
			border-radius: 10rpx;
			box-sizing: border-box;
			background: rgba(0, 0, 0, .05);
		}

		.item-title {
			display: flex;
			justify-content: space-between;
			font-weight: bold;

			view {
				font-size: 34rpx;
			}

			text {
				font-size: 30rpx;
				color: $uni-primary;
			}
		}

		.item-pay {
			font-size: 30rpx;
			line-height: 50rpx;
			font-weight: bold;
			color: $uni-primary;
		}

		.describe {
			margin-top: 25rpx;

			text {
				margin-right: 20rpx;
				font-size: 28rpx;
				color: $uni-black;
			}
		}

		.tags {
			margin-top: 12rpx;

			.tag {
				// background: #F5F5F5;
				margin-right: 10rpx;
				// padding: 2rpx 16rpx;
				height: 42rpx;
				font-size: 24rpx;
				color: $uni-black;
			}
		}

		.boss {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 12rpx;

			.info {
				display: flex;
				width: 50px;
				color: $uni-text-color-grey;

				.pic {
					width: 48rpx;
					height: 48rpx;
					border-radius: 50%;
					margin-right: 16rpx;

					image {
						width: 48rpx;
						height: 48rpx;
						border-radius: 50%;
					}
				}
			}

			.place {
				flex: 1;
				color: $uni-text-color-grey;
				font-size: 24rpx;
				text-align: left;
			}
		}
	}

	.active {
		background: $uni-bg-color-grey;
	}

	.border {
		border-bottom: 1rpx solid $uni-border-color;
		padding: 40rpx 0;
	}
</style>
